package com.deng.api.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * 登录返回实体
 */
@ApiModel
@Data
public class AuthUser implements UserDetails {

    private Long id;

    /**
     *  @JsonIgnore 返回数据忽略password
     */
    @ApiModelProperty("密码（加密）")
    @JsonIgnore
    private String password;

    @ApiModelProperty("账号")
    private String username;

    @ApiModelProperty("昵称")
    private String name;

    @ApiModelProperty("绑定产品ID")
    private Integer productId;

    @ApiModelProperty("所属公司id")
    private Integer companyId;

    @ApiModelProperty("头像地址")
    private String avatar;

    @ApiModelProperty("提示消息")
    private String promptMessage;

    @ApiModelProperty("是否可用")
    private String enabled;

    @ApiModelProperty("上次登录时间")
    private LocalDateTime lastLoginTime;

    @ApiModelProperty("添加日期")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @ApiModelProperty("创建人")
    private String createBy;

    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    @ApiModelProperty("更新人")
    private String updateBy;

    @ApiModelProperty("角色列表")
    @TableField(exist = false)
    private List<SysRole> roles;

    @ApiModelProperty("权限列表")
    @TableField(exist = false)
    private List<SysMenu> menus;

    @Override
    @JsonIgnore
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isEnabled() {
        return true;
    }
}
